package utils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class IntStack {

	private Map<Integer, int[]> map_intArras = new HashMap<Integer, int[]>();
	
	private int MAXLENGTH = 1024;
	
	private int size = 0;
	
	
	public synchronized void addInt(int n){
		int[] array = map_intArras.get(size/MAXLENGTH);
		if(array==null){
			array = new int[MAXLENGTH];
			map_intArras.put(size/MAXLENGTH, array);
		}
		array[size%MAXLENGTH] = n;
		size++;
	}
	
	public synchronized int[] getIntArray(){
		int[] result = new int[size];
		for(int i=0;i<size;i++){
			result[i] = map_intArras.get(i/MAXLENGTH)[i%MAXLENGTH];
		}
		return result;
	}
	
	public static void main(String[] args) {
		IntStack is = new IntStack();
		is.addInt(12);
		is.addInt(13);
		is.addInt(45);
		System.out.println(Arrays.toString(is.getIntArray()));
	}
	
}
